package com.wkck.controller.admin;

import com.wkck.VO.CareerDetailsVo;
import com.wkck.VO.PageResult;
import com.wkck.dto.CareerLikeQueryArgumentsDto;
import com.wkck.dto.SaveAndUpdateCareerDetailsDto;
import com.wkck.result.Result;
import com.wkck.service.CareerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: CK
 * @Date: 2023/12/17/20:31
 * @Description:
 */
@RestController
@RequestMapping("/career")
@Api(tags = "岗位管理")
@CrossOrigin
@Slf4j
public class CareerBgController {

    @Resource
    private CareerService careerService;

    /**
    * @Author: CK
    * @Date: 2023/12/17
    * @Param: []
    * @return: 岗位列表
    * @Description: 岗位列表
    */
    @PostMapping("/list")
    @ApiOperation(value = "岗位列表")
    public Result<PageResult> getCareerList(@RequestBody CareerLikeQueryArgumentsDto careerLikeQueryArgumentsDto) {
        log.info("开始模糊查询岗位列表");
        log.info("参数为: {}", careerLikeQueryArgumentsDto);
        return Result.success(careerService.likeQuery(careerLikeQueryArgumentsDto));
    }

    /**
    * @Author: CK
    * @Date: 2023/12/22
    * @Param: [saveCareerDetailsDto]
    * @return: 成功结果集
    * @Description: 添加岗位
    */
    @PostMapping("/saveCareer")
    @ApiOperation(value = "添加岗位")
    public Result<Boolean> saveCareer(@RequestBody SaveAndUpdateCareerDetailsDto saveCareerDetailsDto) {
        log.info("需要添加的岗位信息: {}", saveCareerDetailsDto);
        return Result.success(careerService.saveCareer(saveCareerDetailsDto));
    }

    /**
    * @Author: CK
    * @Date: 2023/12/29
    * @Param: [id]
    * @return: 
    * @Description: 根据id获取职位信息
    */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取职位信息")
    public Result<CareerDetailsVo> getCareerInfoById(@PathVariable Integer id) {
        log.info("开始进行根据id获取职位信息任务");
        log.info("id为: {}", id);
        return Result.success(careerService.getCareerInfoById(id));
    }

    /**
    * @Author: CK
    * @Date: 2023/12/27
    * @Param: [id, careerDetailsDto]
    * @return: 修改岗位信息标志
    * @Description: 根据ID修改岗位信息
    */
    @PutMapping("/{id}")
    @ApiOperation(value = "根据ID修改岗位信息")
    public Result<Boolean> updateCareerInfoById(
            @PathVariable Integer id,
            @RequestBody SaveAndUpdateCareerDetailsDto careerDetailsDto
    ) {
        log.info("需要修改的岗位id: {}", id);
        log.info("需要修改的岗位信息: {}", careerDetailsDto.toString());
        return Result.success(careerService.updateCareerInfoById(id,careerDetailsDto));
    }

    /**
    * @Author: CK
    * @Date: 2023/12/28
    * @Param: []
    * @return: 删除成功与否的标记
    * @Description: 根据Ids删除岗位
    */
    @DeleteMapping
    @ApiOperation(value = "根据ids删除岗位")
    public Result<Boolean> removeCareerByIds(@RequestBody Map<String,List<Integer>> params) {
        log.info("开始执行 根据ids删除岗位");
        log.info("ids列表: {}", params.get("ids"));
        return Result.success(careerService.removeCareerByIds(params.get("ids")));
    }
}
